package com.springboot.blog.dto;

import java.io.Serializable;

public class Result<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private int code;
    private String message;
    private T data;

    public Result() {
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Result<T> success(String message){
        setMessage(message);
        setCode(200);
        return this;
    }
    public Result<T> error(String message){
        setMessage(message);
        setCode(500);
        return this;
    }
    public boolean hasError(){
        return 500==this.code;
    }
    public boolean succeed(){
        return 200==this.code;
    }
    public T data(){
        return this.data;
    }
    public Result<T> data(T data){
        setData(data);
        return this;
    }
}
